package com.demo01;

import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

public class Demo07 {
    public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //需求：读取配置文件 调用指定类中的对应方法
        //17805973183
        //通过Properties集合 从文件中读取数据
//        Properties
        Properties prop = new Properties();
        //读取文件中的数据到集合中
        prop.load(new FileInputStream("D:\\Coding\\Project\\IdeaProjects\\JavaWeb2012\\Demo0315\\src\\main\\resources\\propeties.txt"));
        //获取键对应的值
        String className = prop.getProperty("className");
        String methodName = prop.getProperty("methodName");
        System.out.println(className);
        System.out.println(methodName);
        //1.获取Person.class字节码文件对象
        Class c = Class.forName(className);
        //2.获取构造方法
        Constructor con = c.getConstructor(String.class, int.class, String.class);
        //3.创建对象
        Object obj = con.newInstance("小明", 12, "福州");
        System.out.println(obj);
        //4.获取指定的方法
        Method method5 = c.getDeclaredMethod(methodName, null);
        method5.setAccessible(true);
        method5.invoke(obj, null);
    }
}
